//
//  BaseTableViewController.swift
//  WeiBo
//
//  Created by 史亚洲 on 16/1/10.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController, VisitorLoginViewDelegate {
    //定义用户是否登录的标志
    var userLogin = false
    
    //访客视图
 var  vistorLoginView: VisitorLoginView?
    
    
    //loadView
    //1. -苹果专门为 手写代码准备的 一旦实现该方法 sb / xib 会自动失效
    //2. 准备视图层次结构 在UIViewController 中 会将view 准备出来
    //3.在super.loadView之前 view没有被创建出来(nil) 追踪view 会造成递归调用
    override func loadView() {
        super.loadView()
        //自定义view
        if userLogin {
        //创建tableView
            super.loadView()
            //print(view)
     
        
        }else{
        
            //自定义访客视图
            vistorLoginView = VisitorLoginView()
            
            //设置代理
            vistorLoginView?.visitorViewDelegate = self
            
            view = vistorLoginView
            
            
            self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "userWillLogin")
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "userWillRegister")
        
        }
        
      
    }
    func userWillLogin() {
        print(__FUNCTION__)
        let oauth = OAuthViewController()
        let nav = UINavigationController(rootViewController: oauth)
        presentViewController(nav, animated: true, completion: nil)
    }
    func userWillRegister() {
        print(__FUNCTION__)

    }
    //在这个方法中,设置view的大小
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        print(view)
        print(view.classForCoder)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

          }
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }

    /*
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)

        // Configure the cell...

        return cell
    }
    */

    /*
    // Override to support conditional editing of the table view.
    override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return false if you do not want the specified item to be editable.
        return true
    }
    */

    /*
    // Override to support editing the table view.
    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == .Delete {
            // Delete the row from the data source
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        } else if editingStyle == .Insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }    
    }
    */

    /*
    // Override to support rearranging the table view.
    override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {

    }
    */

    /*
    // Override to support conditional rearranging of the table view.
    override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return false if you do not want the item to be re-orderable.
        return true
    }
    */

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
